//
//  BCBaseHttpEngine.h
//  BCBaseNetworking
//
//  Created by Basic on 15/5/5.
//  Copyright (c) 2015年 &#24555;&#26234;&#38598;&#22242;. All rights reserved.
//  网络请求管理类
//

#import "BCBaseRequestOperation.h"
#import "BCHttpRequestModel.h"
//#import "AFHTTPSessionManager.h"
#import <AFNetworking/AFHTTPSessionManager.h>

#define BCBaseHttpEngineInstance               [BCBaseHttpEngine sharedInstance]

@interface BCBaseHttpEngine : NSObject
/**
 *  串行队列，存放有序的请求
 */
@property (nonatomic, strong) NSOperationQueue      *httpSerialQueue;
/**
 *  并发队列，存放无序的请求
 */
@property (nonatomic, strong) NSOperationQueue      *httpConcurrentQueue;
/**
 *  消息队列
 */
@property (nonatomic, strong) NSOperationQueue      *msgQueue;
@property (nonatomic, strong, readonly) AFHTTPSessionManager  *bcSessionManager;/**< Session */


#pragma mark - system
/**
 *  @brief  获取默认请求管理类实例，调用方也可以自己定义
 *
 *  @return instancetype
 */
+ (instancetype )sharedInstance;
/**
 *  @brief   销毁
 */
- (void)destory;

#pragma mark - 发送请求,子类可以override
/**
 根据url、API等等参数 发post api请求,子类可以override

 @param url url
 @param api api名称
 @param param 参数集合
 @param method method类型
 @param constructAction 构造action
 @param successAction 成功action
 @param errorAction 失败cation
 @param target 请求所属target
 @return BCBaseRequest
 */
+ (BCBaseRequestOperation *)bc_sendRequestWithURL:(NSString *)url withApi:(NSString *)api withParam:(NSMutableDictionary *)param withMethod:(BCBaseRequestMethod)method withConstruct:(void(^)(BCHttpRequestModel *requestModel))constructAction withSuccess:(void(^)(BCBaseRequestOperation *request, BCHttpResponseModel *response))successAction withError:(void(^)(BCBaseRequestOperation *request, BCHttpResponseModel *response))errorAction withComplate:(void(^)(BCHttpRequestModel *request, BCHttpResponseModel *response))complate  withTarget:(id )target;

/**
 ，包含多部分 NSURLRequest
 
 @param method method description
 @param path path description
 @param parameters parameters description
 @param block block description
 @return return value description
 */
- (NSMutableURLRequest *)loadMultiFormRequestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block;

#pragma mark - 根据 requestModel 生成 BaseRequest 添加到队列中
/**
 *  @brief  根据requestModel、httpclient 构建BaseRequest,添加到队列中
 *
 *  @param requestModel  请求数据模型
 *  @return BCBaseRequest
 */
- (BCBaseRequestOperation *)bc_addBaseRequest:(BCHttpRequestModel*)requestModel;

#pragma mark - 请求回调
/**
 *  请求完成回调
 *
 *  @param request      request对象
 *  @param response     response 对象
 *  @param responseData response数据
 *  @param error        错误信息
 */
- (void)bc_onRequestComplate:(BCBaseRequestOperation *)request withResponse:(NSURLResponse *)response withResponseData:(id )responseData withError:(NSError *)error;

#pragma mark - 移除请求
/**
 通过tag 移除指定的请求

 @param tag 请求的kdTag
 */
- (void)bc_removeRequestWithTag:(id)tag;

/**
 *  @brief  通过target 移除请求
 *
 *  @param target 回调接受对象
 */
- (void)bc_removeRequest:(id)target;

@end

